<?php

namespace App\Admin\Controllers;

use App\Admin\Contracts\UserInterface;
use App\Base\Controllers\Controller;
use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * 用户接口
     * @return UserInterface
     */
    public function getUserInterface()
    {
        return app()->make(UserInterface::class);
    }

    /**
     * 获取用户列表
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request)
    {
        if ($request->getMethod() == "POST") {


        }
        $where = function ($query) {

        };
        return $this->getUserInterface()->getList($where);
    }

    /**
     * 添加
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function add(Request $request)
    {
        if ($request->getMethod() == "POST") {
            return $this->getUserInterface()->addOne($request->all());
        }
        return view("admin.user.add");
    }

    /**
     * 编辑
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function edit(Request $request)
    {
        if ($request->getMethod() == "POST") {
            return $this->getUserInterface()->editOne($request->all());
        }
        return view("admin.user.edit");
    }

    /**
     * 用户删除
     * @param Request $request
     */
    public function del(Request $request)
    {
        return $this->getUserInterface()->delOne($request->all());
    }
}